package com.jinpin.core.enums;

import java.util.Objects;

public enum ResultEnum {

    LOGIN_SUCCESS(200L,"登录成功"),
    SUCCESS(200L, "操作成功"),
    FAILED(500L, "操作失败"),
    VALIDATE_FAILED(404L, "参数检验失败"),
    UNAUTHORIZED(401L, "暂未登录或token已经过期"),
    FORBIDDEN(403L, "没有相关权限");

    private Long code;
    private String msg;

    ResultEnum(Long code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Long getCode() {
        return code;
    }


    public static String getMsg(Long code) {
        for (ResultEnum r : values()) {
            if (Objects.equals(r.code, code)) {
                return r.getMsg();
            }
        }
        return null;
    }

    public static Long getCode(String msg) {
        for (ResultEnum r : values()) {
            if (r.getMsg().equals(msg)) {
                return r.getCode();
            }
        }
        return null;
    }





    public void setCode(Long code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
